import java.io.*;

public class Main {
    public static void main(String[] args) {
        FileInputStream fis = null;
        FileOutputStream fos = null;

        try {
            // 输入和输出文件路径
            File inputFile = new File("source.txt");
            File outputFile = new File("destination_byte_stream.txt");

            // 创建输入流和输出流
            fis = new FileInputStream(inputFile);
            fos = new FileOutputStream(outputFile);

            int byteData;
            // 逐字节读取并写入文件
            while ((byteData = fis.read()) != -1) {
                fos.write(byteData);
            }

            System.out.println("File copied using Byte Stream successfully.");
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (fis != null) fis.close();
                if (fos != null) fos.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
